package com.corecloud.mapper.mysql;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.corecloud.entity.SysPermissionEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 *
 * 权限相关
 * @author CCW
 * @email 452050507@qq.com
 * @date 2020-08-25 11:14:24
 */
@Mapper
public interface SysPermissionMapper extends BaseMapper<SysPermissionEntity> {



	/**
	 * 根据条件查询SysPermissionEntity信息
	 *
	 * @param map
	 * @return SysPermissionEntity信息集合
	 */
	@Select({"<script>select * from sys_permission ",
			"where 1=1 ",
			"<if test='id !=null'> and id = #{id} </if>",
			"<if test='url != null and url != \"\" '> and url like CONCAT('%',#{url},'%') </if>",
			"<if test='name != null and name != \"\" '> and name like CONCAT('%',#{name},'%') </if>",
			"<if test='isValid !=null'> and is_valid = #{isValid} </if>",
			"<if test='parentId !=null'> and parent_id = #{parentId} </if>",
			"<if test='type !=null'> and type = #{type} </if>",
			"</script>"})
	List<SysPermissionEntity> getListByParas(Map<String, Object> map);


	/**
	 * 根据用户ID获取对应生效的权限信息
	 * @param map
	 * @return
	 */
	@Select({"<script>SELECT sp.* FROM sys_user_role sur ",
			"left join sys_permission_role spr ON spr.rid = sur.role_id ",
			"left join sys_permission sp ON sp.id = spr.pid ",
			"WHERE ",
			"sur.user_id = #{uid} ",
			"and sp.is_valid = 1 ",
			"and sp.type = #{permissionType} ",
			"<if test='grade !=null'> and sp.grade = #{grade} </if> ",
			" GROUP BY sp.id ",
			"</script>"})
	List<SysPermissionEntity> getListByUserParas(Map<String, Object> map);

}
